﻿using System;
using System.Collections.Generic;
using AMM.CustomClassLibrary;
using AMM.DataAccess;
using AMM.Model;

namespace AMM.Business {
    public class ReportProcessor : BaseProcessor {

        private ReportRepository _reportRepository;

        public ReportProcessor() {
            this._reportRepository = new ReportRepository();
        }

        public List<MaterialStoreView> GetMaterialStoreViewList(
            string materialCode
            , string storeBasisCode
            , decimal? quantityStart
            , decimal? quantityEnd) {
            try {
                return this._reportRepository.GetMaterialStoreViewList(materialCode, storeBasisCode, quantityStart, quantityEnd);
            }
            catch (Exception ex) {
                Logger.Error(ex.Message, ex);
                throw new Exception("获取报表数据失败！");
            }
        }

        public List<ProductStoreView> GetProductStoreViewList(
            string productCode
            , string storeBasisCode
            , decimal? quantityStart
            , decimal? quantityEnd) {
            try {
                return this._reportRepository.GetProductStoreViewList(productCode, storeBasisCode, quantityStart, quantityEnd);
            }
            catch (Exception ex) {
                Logger.Error(ex.Message, ex);
                throw new Exception("获取报表数据失败！");
            }
        }

        public List<RequirementAnalysis_Result> GetRequirementAnalysisProcedureList(
            int conditionType
            , string materialCode
            , string produceConducts) {
            try {
                return this._reportRepository.GetRequirementAnalysisProcedureList(
                    conditionType
                    , string.IsNullOrEmpty(materialCode) ? null : materialCode
                    , string.IsNullOrEmpty(produceConducts) ? null : produceConducts);
            }
            catch (Exception ex) {
                Logger.Error(ex.Message, ex);
                throw new Exception("获取报表数据失败！");
            }
        }

        public List<SuspenseUnQualifiedView> GetSuspenseUnQualifiedViewList(
            string materialCode
            , int? vendorId) {
            try {
                return this._reportRepository.GetSuspenseUnQualifiedViewList(materialCode, vendorId);
            }
            catch (Exception ex) {
                Logger.Error(ex.Message, ex);
                throw new Exception("获取报表数据失败！");
            }
        }

        public List<BOMCostView> GetBOMCostViewList(string bomCode, string orderBy) {
            try {
                return this._reportRepository.GetBOMCostViewList(bomCode, orderBy);
            }
            catch (Exception ex) {
                Logger.Error(ex.Message, ex);
                throw this.BuildException("获取报表数据失败！");
            }
        }

        public List<ProduceConductCostView> GetProduceConductCostViewList(string produceConductCode) {
            try {
                return this._reportRepository.GetProduceConductCostViewList(produceConductCode);
            }
            catch (Exception ex) {
                Logger.Error(ex.Message, ex);
                throw this.BuildException("获取报表数据失败！");
            }
        }
    }
}
